/**
 * This software implements a CAT-1 LTE baseband.
 *
 * crc24.h --
 *
 * Copyright (C) 2015  Optimum Semiconductor Technologies, Inc. info@optimumsemi.com

 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.

 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

#ifndef __CRC_
#define __CRC_

#define GPOLY0 0x1864CFB
#define GPOLY1 0x1800063

void crc24_func(unsigned char * input, int length, char * crc);

//16 bit CRC implementations (used with different interfaces):
unsigned short LteDl_crc16_ref_LTE_general(unsigned char* in, int num_bits);
unsigned short LteDl_crc16_ref_LTE(unsigned char* in,int num_bytes);
unsigned short LteDl_crc16_LTE(unsigned char* in, unsigned short gen, int num_bytes);

unsigned short LteDl_crc16_LTE_32(unsigned int * in, unsigned short gen_poly, int num_info_bits);
unsigned short LteDl_crc16_LTE_32_rev(unsigned int * in, unsigned short gen_poly, int num_info_bits);

//Unoptimized 24 bit CRC's (A & B) for reference:
void LteDl_crc24_0_LTE(unsigned char* in, int input_len, unsigned char* result);
void LteDl_crc24_1_LTE(unsigned char* in, int input_len, unsigned char* result);

//Optimized 24 bit vectorized CRC code:
void LteDl_initCRC24_rem_tbl(unsigned int Gpoly, unsigned char* tmp_buf, unsigned int* rem_tbl, int num_bytes);
void LteDl_crc24_table_gen(unsigned int Gpoly, unsigned int * table);

int LteDl_crc24_opt(unsigned char* in,unsigned int* crc24_tbl,int num_bytes);
unsigned int LteDl_crc24_LTE_opt(unsigned char* in, unsigned int* rem_tbl, unsigned int* crc_tbl, int num_bytes);
unsigned int LteDl_crc24_LTE_asm(unsigned char* in, unsigned int* rem_tbl, unsigned int* crc_tbl, int num_bytes);

void LteDl_bit_to_char(unsigned char *in,unsigned char *out,int number_bits);

#endif

